package com.jmp.api.controller;

import com.jmp.api.service.SunCodeDeleteService;
import com.jmp.api.service.SunCodeService;
import com.jmp.base.SunCodeApi;
import com.jmp.base.dto.*;
import lombok.extern.slf4j.Slf4j;
import one.stand.model.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SunCodeController implements SunCodeApi {
    @Autowired
    private SunCodeService sunCodeService;
    @Autowired
    private SunCodeDeleteService sunCodeDeleteService;

    @Override
    public ResultModel<SunCodeGoodsResponse> goods(@RequestBody SunCodeGoodsRequest request) {
        String codeUrl = sunCodeService.goodsSuncode(request.getSpecId(), request.getCardId());
        SunCodeGoodsResponse response = SunCodeGoodsResponse.builder().codeUrl(codeUrl).build();
        return ResultModel.success(response);
    }

    @Override
    public ResultModel<SunCodeCardResponse> card(@RequestBody SunCodeCardRequest request) {
        String codeUrl = sunCodeService.getWxTwoCode(request.getCardId(), request.isUpdateFlag());
        SunCodeCardResponse response = SunCodeCardResponse.builder()
                .codeUrl(codeUrl)
                .build();
        return ResultModel.success(response);
    }

    @Override
    public ResultModel<SunCodeCardResponse> company(@RequestBody SunCodeCompanyRequest request) {
        String codeUrl = sunCodeService.companyCode(request.getCardId(), request.getCompanyId(), request.getLogo());
        SunCodeCardResponse response = SunCodeCardResponse.builder()
                .codeUrl(codeUrl)
                .build();
        return ResultModel.success(response);
    }

    @Override
    public ResultModel delete(@RequestBody SunCodeDeleteRequest request) {
        sunCodeDeleteService.delete(request.getCompanyId());
        return ResultModel.success();
    }
}
